package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.UserDao;
import com.qf.entity.Page;
import com.qf.entity.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {
    @Autowired
    @Qualifier("userDao")
    private UserDao userDao;


    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public PageInfo<User> findAll(Integer page, Integer limit) {
//        设置页码 和页大小
        PageHelper.startPage(page, limit);
        List<User> list = userDao.findAll();
        System.out.println(list + "service");
        return new PageInfo<User>(list);
    }


    @Override
    public User find(Integer id) {
        return userDao.find(id);

    }

    @Override
    public int userById(User user) {
        return userDao.update(user);

    }

    @Override
    public int deleteUsers(Integer id) {
        return userDao.deleteUsers(id);
    }


    @Override
    public int insertUser(User user) {
        return userDao.insertUser(user);
    }

    @Override
    public int update(User user) {
        return userDao.update(user);
    }

}
